import ajax from '@/utils/ajax'
// import { genUUID } from "@/utils/common";

export const submit = async (list) => {
  const data = JSON.parse(JSON.stringify(list))
  // 题目标题自动增加索引
  data.forEach((item, index) => {
    if (item.componentName !== 'custom-question' && item.autoIndex) {
      item.title = `${index}.${item.title}`
    }
  })
  const res = await ajax.post('/api/v1/fe/lowcode/save.do', {
    data,
  })
  return res.result
}

export const edit = async (record, id) => {
  const res = await ajax.post('/api/v1/fe/lowcode/edit.do', {
    data: { record, id },
  })
  return res
}

export const getById = async (id) => {
  if (!id) return null
  const res = await ajax.get('/api/v1/fe/lowcode/getById.do', {
    params: {
      id,
    },
  })

  return res.result
}

export const preview = async (id) => {
  const res = await ajax.get('/api/v1/fe/lowcode/preview.do', {
    params: {
      questionnaireId: id,
    },
  })

  return res.result
}

export const delQuestion = async (data) => {
  const res = await ajax.post('/api/v1/fe/lowcode/delete.do', {
    data,
  })
  return res
}

export const getQuestionnaireList = async () => {
  const res = await ajax.get('/api/v1/fe/lowcode/list.do')
  // console.log('res', res)
  return res.result
}

export const deployQuestion = async (record, id) => {
  const res = await ajax.post('/api/v1/fe/lowcode/deploy.do', {
    data: { record, id },
  })
  return res.result
}
